package cn.vshare.service.impl;

import cn.vshare.dao.TipsDao;
import cn.vshare.entity.Tips;
import cn.vshare.service.TipsService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

@Service("tipsService")
public class TipsServiceImpl implements TipsService {

    @Autowired
    private TipsDao tipsDao;

    @Override
    public Page<Tips> getTips(Map<String, Object> map) {
        Page<Tips> tipsPage = new Page<Tips>();
        int totalRows = tipsDao.countTips(map); //获取总行数
        int pageSize = (int) map.get("pageSize");
        int currPage = (int) map.get("currPage");
        tipsPage = PageHelper.startPage(currPage,pageSize);
        int totalPage = totalRows % pageSize == 0 ? totalRows / pageSize : totalRows / pageSize + 1; //计算总页数
        tipsPage.setTotal(totalRows); //添加总行数
        tipsPage.setPageNum(totalPage); //添加总页数
        List<Tips> list = tipsDao.getTips(map);
        return tipsPage;
    }

    @Override
    public void handleTips(Map<String, Object> map) {
        tipsDao.handleTips(map);
    }

    public TipsDao getTipsDao() {
        return tipsDao;
    }

    public void setTipsDao(TipsDao tipsDao) {
        this.tipsDao = tipsDao;
    }
}
